package com.parlons.activities;

/**
 * Created by wangyifan on 15/12/24.
 */

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.parlons.R;
import com.parlons.SmackServices;

@SuppressLint("NewApi")
public class SettingsFragment extends Fragment {

    public static View view;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.settings, container, false);
        Button logOutButton = (Button) view.findViewById(R.id.log_out_button);
        logOutButton.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        SmackServices.getConnection().disconnect();
                        // set default user
                        SharedPreferences settings = getActivity().getSharedPreferences("parlons", Activity.MODE_PRIVATE);
                        SharedPreferences.Editor editor = settings.edit();
                        editor.putString("default_user", null);
                        editor.putString("password", null);
                        editor.commit();

                        getActivity().startActivity(new Intent(getActivity(), SplashActivity.class));
                        System.exit(0);
                    }
                }

        );

        return view;

    }

}
